// recruitmentest/pages/consultation/technological/technological.js
import {
  ApiRootUrl,
  apiList
} from '../../../../config/index.js'
import Dialog from '../../../../@vant/weapp/dialog/dialog';
import {
  IMG_PATH
} from '../../../../config/index.js'
import {
  request,formatStringTime
} from "../../../../utils/util.js"
import Toast from '../../../../@vant/weapp/toast/toast';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    id:'',
    code:'',
    title:'',
    content:'',
    feedbackStr:'',
    params:{}
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
let id=options.id
let code=options.code
console.log(options);
this.setData({
  id:id,
  code:code,
})
this.getMicroInfoById(id)
  },
  getMicroInfoById(id){
    let self = this;
    wx.request({
      url: `${ApiRootUrl}/labourMicro/queryMicroInfoById/${id}`,
      method: 'get',
      success(res) {
        if (res.data.code == 20000) {
          console.log(res.data.data);
          let title=res.data.data.labourName+'的'+res.data.data.name+'的劳动咨询'
          self.setData({
            title:title,
            content:res.data.data.content,
            params:res.data.data
          })
        } else {
          Toast({
            duration: 3000,
            forbidClick: true,
            type: 'fail',
            message: res.data.message,
          });
        }
      },
      fail(res) {
        Toast({
          duration: 3000,
          forbidClick: true,
          type: 'fail',
          message: '网络错误',
        });
      }
    })
  },
  submit(){
    let self=this
    Toast.loading({
      duration: 0,
      message: '加载中...',
      forbidClick: true,
    });

    let params=JSON.parse(JSON.stringify(self.data.params))
    params.rebackContent=self.data.feedbackStr
    if(!params.rebackContent){
      Toast.clear();
      Toast({
        type: 'fail',
        duration: 3000,
        message: '请输入处理内容！',
      });
      return
    }
    wx.request({
      url: `${ApiRootUrl}/labourMicro/addHandleLabourMicro`,
      method: 'POST',
      header: {
        'content-type': 'application/json; charset=utf-8',
        'cookie': wx.getStorageSync("sessionid")
      },
      data:params,
      success(res) {
        if(res.data.code == 20000){
          Toast.clear();
          Toast({
            type: 'success',
            duration: 3000,
            message: '提交成功',
          });
          setTimeout(()=>{
            wx.navigateBack()
          },3000) 
        }else{
          Toast.clear();
          Toast({
            duration: 3000,
            forbidClick: true,
            type: 'fail',
            message: res.data.message,
          });
        }
      },
      fail(res){
        Toast.clear();
        Toast({
          duration: 3000,
          forbidClick: true,
          type: 'fail',
          message: '网络已断开',
        });
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})